<?php 
        $sMonHocs=  MonHoc::model()->findAll();
        $sKhoiHoc=  KhoiHoc::model()->findAll();
?>

<style type="text/css">
    .search label{
        font-weight: bold;
        display: block;
        margin-top: 4px;
        margin-bottom: 2px;
    }
</style>

<div class="search">
        <form action="<?php echo Yii::app()->createUrl('site/search') ?>" method="get" onsubmit="return onSubmit();">
        <input id="searchInput" type="text" name="keyword" value="<?php echo isset($keyword)?$keyword:"" ?>">
        <input id="searchSubmit" type="submit" value="Tìm" name="submit" style="margin-top: 5px">
        <br>
        <br>
        <a id="search-advance">Hiện tìm kiếm nâng cao</a>

        <div id="search-advance-input" style="display:none; margin-top: 5px">
                <label>Search in</label>
                <?php echo CHtml::dropDownList('mhid', '', CHtml::listData($sMonHocs, 'id', 'name'), array('empty'=>'Tất cả', 'id'=>'slt-mh', 'style'=>'width:100%')) ?>

                <label>And in</label>
                <?php echo CHtml::dropDownList('khid', '', CHtml::listData($sKhoiHoc, 'id', 'name'), array('empty'=>'Tất cả', 'id'=>'slt-kh', 'style'=>'width:100%')) ?>

                <div id="mhchild" style="display:none">
                    <label>And in</label>
                    <?php echo CHtml::dropDownList('mhcid', '', array(), array('empty'=>'', 'id'=>'slt-mhc')) ?>
                </div>
        </div>

        </form>
</div>

<script type="text/javascript">
        $(function(){
                $('#search-advance').click(function(){
                        $('#search-advance-input').toggle();
                        
                        if($('#search-advance-input').is(':visible')){
                                $(this).text('Ẩn tìm kiếm nâng cao');
                        }else{
                                $(this).text('Hiện tìm kiếm nâng cao');
                        }                        
                });
                
                $('#slt-mh').change(function(){
                        $.ajax({
                                'url':'<?php echo Yii::app()->createUrl('site/getMonHocChildSelectHtmlOptions') ?>/monhocId/'+$(this).val(),
                                'success':function(data){                                        
                                        $('#slt-mhc').html(data);
                                        if(data){
                                                $('#mhchild').show();
                                        }else{
                                                $('#mhchild').hide();
                                        }
                                        
                                }
                        });
                });
        });
        
        function onSubmit(){
                if($('#searchInput').val()!='' || $('#slt-mh').val()!='' || $('#slt-kh').val()!='' || $('#slt-mhc').val()!=''){
                        return true;
                }
                
                return false;
        }
</script>